<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
     canvas{
       border: 2px solid blue;
     }
  </style>
</head>
<body>
     <canvas width="500" height="500"></canvas>
     <script>
        var canvas = document.querySelector('canvas')
        var ctx = canvas.getContext('2d')
        //绘制矩形：无填充,参数为 左上点坐标和宽高
        ctx.strokeRect(100,100,200,200) 
        //填充矩形：默认黑色
        ctx.fillStyle = 'red'
        ctx.fill()
        ctx.fillRect(100,100,200,200)
     </script>
</body>
</html>